package com.blog.admin.controller;

import com.blog.admin.service.BlogMessageService;
import com.blog.admin.vo.BlogMessageVO;
import com.blog.util.Result;
import com.blog.vo.PageVO;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.HashMap;
import java.util.Map;

/**
 * @author tangqj
 * @Description
 * @create 2020/2/18 15:14
 */
@RestController
@RequestMapping("blogMessageController")
public class BlogMessageController {
    @Autowired
    BlogMessageService blogMessageService;


    @RequestMapping("getBlogMessage")
    public Map<String,Object> getBlogMessage(PageVO page,BlogMessageVO blogMessageVO){
        PageInfo<BlogMessageVO> result = blogMessageService.getBlogMessage(page,blogMessageVO);
        Map<String,Object> data = new HashMap<>();
        data.put("count", result.getTotal());
        return Result.responeAjaxMap(true,"", result.getList(),data);
    }

    @RequestMapping("insertBlogMessage")
    public Map<String,Object> insertBlogMessage(BlogMessageVO blogMessageVO){
        boolean result = blogMessageService.insertBlogMessage(blogMessageVO);
        return Result.responeAjaxMap(result,  result?"操作成功":"操作失败", "",null);
    }

    @RequestMapping("deleteBlogMessageById")
    public Map<String,Object> deleteBlogMessageById(String id){
        boolean result = blogMessageService.deleteBlogMessageById(id);
        return Result.responeAjaxMap(result,  result?"操作成功":"操作失败", "",null);
    }
}
